import requests
#全局变量sess
sess = requests.session()
rp = sess.request("get",url="http://www.baidu.com")
ip = "192.168.1.231"
#普通的GET类型接口
def gettest():
    #get请求参数  存入params变量
    params ={"id":1}
    sess.request("get",url="http://192.168.1.231:8080/pinter/com/getSku",params=params)
    print(rp.text)

#参数为k=v的POST接口
def posttest():
    #post请求参数  用data传参
    data = {'userName':"admin",'password':"123456"}
    rp = sess.request("post","http://192.168.1.231:8080/pinter/com/login",data=data)
    print(rp.text)
#参数为json的POST接口
def post_json_test():
    #传json参数，使用json变量进行传参
    json = {"userName":"test","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"Beijing"}
    rp = sess.request("post","http://192.168.1.231:8080/pinter/com/register",json=json)
    print(rp.text)
#参数为k=json的POST接口
def key_json_post():
    data = {'param': {"skuId":123,"num":10}}
    rp = sess.request('post',"http://"+ip+":8080/pinter/com/buy",data=data)
    print(rp.text)
#返回json数组的GET接口
def gettest_json():
    params ={"genderType":0}
    rp = sess.request("get",url="http://"+ip+":8080/pinter/com/userList",params=params)
    print(rp.text)
if __name__ == '__main__':
    gettest_json()